import 'base/axis.dart';

/// 配置Y轴相关数据
///
/// Created by wanggaowan on 2023/9/15 09:49
class YAxis extends BaseYAxis {
  YAxis({super.lineColor,
    super.lineWidth,
    super.lineDash,
    super.startPadding,
    super.endPadding,
    // 轴上标签数量。比如设置标签数量为6，如果使用默认的ValueFormatter,设置Y轴最小、最大值分别为0、100，则Y轴标签值为0，20，40，60，80，100
    super.labelCount,
    super.labelTextSize,
    super.labelColor,
    super.labelOffsetAxis,
    AxisValueFormatter? axisValueFormatter,
    super.labelAlign,
    super.labelOverAlign,
    super.labelMaxLines,
    super.textOverflow,
    super.gridLineColor,
    super.gridLineWidth,
    super.gridUseEndPadding,
    super.gridUseStartPadding,
    super.gridLineDash,
    super.labelWidth,
    super.labelMinWidth,
    super.labelMaxWidth,
    super.labelVerticalPadding,
    this.min = 0,
    this.max = 100})
      : super(
    axisValueFormatter: axisValueFormatter ??
            (int position) {
          if (labelCount <= 0) {
            return Label();
          }

          if (labelCount == 1 || position == 0) {
            return Label(value: min.round().toString());
          }

          if (position == labelCount - 1) {
            return Label(value: max.round().toString());
          }

          var step = (max - min) / (labelCount - 1);
          if (step < 0) {
            step = 0;
          }
          return Label(
              value: (min + (position * step)).round().toString());
        },
  );

  /// 绘制坐标起始值
  final double min;

  /// 绘制坐标结束值
  final double max;
}

/// 横向图表的Y轴
///
/// Created by wanggaowan on 2023/12/1 11:34
class HorizontalYAxis extends BaseYAxis {
  HorizontalYAxis({super.lineColor,
    super.lineWidth,
    super.lineDash,
    super.startPadding,
    super.endPadding,
    super.labelCount,
    super.labelTextSize,
    super.labelColor,
    super.labelOffsetAxis,
    super.axisValueFormatter,
    super.labelAlign,
    super.labelOverAlign,
    super.labelMaxLines,
    super.textOverflow,
    super.gridLineColor,
    super.gridLineWidth,
    super.gridUseEndPadding,
    super.gridUseStartPadding,
    super.gridLineDash,
    super.labelWidth,
    super.labelMinWidth = 0,
    super.labelMaxWidth,
    super.labelVerticalPadding});
}
